package com.example.chao.myphotosearch.api;

import android.util.Log;

import com.example.chao.myphotosearch.interfaces.RequestCancelListener;
import com.example.chao.myphotosearch.interfaces.SubscriberDoOnNextListener;

import rx.Subscriber;

/**
 * Created by chao on 2016/3/30.
 */
public class HttpSubscribe<T> extends Subscriber<T> implements RequestCancelListener {
    private SubscriberDoOnNextListener<T> nextListener;
    public HttpSubscribe(SubscriberDoOnNextListener<T> nextListener){
        this.nextListener = nextListener;
    }
    @Override
    public void onCompleted() {

    }

    @Override
    public void onError(Throwable e) {
        Log.e("onError", e.getMessage());
    }

    @Override
    public void onNext(T t) {
        if(nextListener!=null){
            nextListener.doOnNext(t);
        }
    }

    @Override
    public void cancel() {
        if(!isUnsubscribed()){
            unsubscribe();
        }
    }
}
